#include "GameManager.h"


#include "_Global/Socket/Common.h"
#include "_Global/Socket/ClientSocket.h"
#include "_Global/Sqlite/Sqlite.h"


//#include <QtCore> //包含所有常用
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickWindow>
//#include <QQuickView>

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
#include <QSqlResult>

#include <QMessageBox>
#include <QFileInfo>
#include <QDir>



GameManager::GameManager(QObject *parent) :
    QObject(parent), m_ConfigFile(FIXLOCALPATH_R("Config.cfg"))
{
    m_pGameWindow = nullptr;
    m_pGameCore = nullptr;
    m_pUserInfo = nullptr;
    m_pSqliteDB = nullptr;
    m_pPlatform = nullptr;
    m_pInfoSocket = nullptr;
    m_pGameSocket = nullptr;

    m_pAppQmlEngine = nullptr;
}


GameManager::~GameManager()
{
    //释放顺序:必须是总->分 或 使用->被使用 的顺序
    if(m_pAppQmlEngine != nullptr)
    {
        delete m_pAppQmlEngine;
        m_pAppQmlEngine = nullptr;
    }
    if(m_pGameCore != nullptr)
    {
        delete m_pGameCore;
        m_pGameCore = nullptr;
    }
    if(m_pUserInfo != nullptr)
    {
        delete m_pUserInfo;
        m_pUserInfo = nullptr;
    }
    if(m_pPlatform != nullptr)
    {
        delete m_pPlatform;
        m_pPlatform = nullptr;
    }
    if(m_pSqliteDB != nullptr)
    {
        delete m_pSqliteDB;
        m_pSqliteDB = nullptr;
    }
    if(m_pInfoSocket != nullptr)
    {
        delete m_pInfoSocket;
        m_pInfoSocket = nullptr;
    }
    if(m_pGameSocket != nullptr)
    {
        delete m_pGameSocket;
        m_pGameSocket = nullptr;
    }
}

bool GameManager::InitOnce()
{
    //QML中可以使用下列类的 枚举
    //qmlRegisterType<_Pet>("cn.leamus.gamedata",1,0,"PetClass");
    qmlRegisterUncreatableType<Game>("cn.leamus.gamedata",1,0,"GameCoreClass","Error Create Game Class");
    qmlRegisterUncreatableType<UserInfo>("cn.leamus.gamedata",1,0,"UserInfoClass","Error Create UserInfo Class");
    qmlRegisterUncreatableType<GameManager>("cn.leamus.gamedata",1,0,"GameManagerClass","Error Create GameManager Class");
    qmlRegisterUncreatableType<_Platform>("cn.leamus.gamedata",1,0,"PlatformClass","Error Create Platform Class");
    //qmlRegisterUncreatableType<_Common>("cn.leamus.gamedata",1,0,"CommonClass","Error Create Common Class");


    //要在 信号/槽/属性 的参数中使用，或者qml中使用下列类型的函数或数据，则注册一下！字符串名不能随意更改!
    /*
     * 1.enum类型:
     *      如果信号槽的参数要使用Q_ENUMS或Q_FLAGS,需要注册一下!
     *      注册方法:如果有 类前缀,参数中不能使用 类前缀!!!比如只能:
     *          qRegisterMetaType<[类名::]enum名>("enum名");
     *      注意:如果enum类型是全局的,则在QML中的值是QVariant!?
     * 2.类 类型:
     *      QML中需要使用其类的函数,或信号槽的参数中需要使用其类型,则需要注册一下:
     *      注册方法:如果有 类前缀,参数中必须要有 类前缀!!!比如:
     *          qRegisterMetaType<[类名::]类名>("[类名::]类名");
    */
    qRegisterMetaType<QObjectList>("QObjectList");          //qml中使用其函数
    qRegisterMetaType<QStandardPaths::StandardLocation>("QStandardPaths_StandardLocation");
    qRegisterMetaType<GameModel::_GameStatus>("GameModel_GameStatus");
    qRegisterMetaType<_ClientGroupStatus>("_ClientGroupStatus");
    qRegisterMetaType<PlayerInfo*>("PlayerInfo*");
    //qRegisterMetaType<_SaveToNetDBDataType>("_SaveToNetDBDataType");
    //qRegisterMetaType<_BaseObject::_ObjType>("_ObjType");    //信号/槽参数中使用




    //pGameThread = new QThread(this);

    m_pGameCore = new Game(this);
    m_pUserInfo = new UserInfo(this);
    m_pPlatform = new _Platform(this);


    //m_pGameCore->m_pGameModel = new GameModel(this);

    //m_pGameCore->pConfig = &config;
    //m_pUserInfo->pConfig = &config;



    m_pUserInfo->m_pInfoSocket = m_pInfoSocket = new TcpSocket(this);
    m_pUserInfo->m_pGameSocket = m_pGameSocket = new TcpSocket(this);

    m_pGameCore->m_pGameSocket = m_pGameSocket;

    m_pInfoSocket->m_baPackageHeaderFlag.setRawData("LMS",3);
    m_pGameSocket->m_baPackageHeaderFlag.setRawData("LMS",3);

    m_pGameSocket->startKeepAlive(600000, "H", 1);


//读取游戏配置(Sqlite)
    m_pSqliteDB = m_pUserInfo->m_pSqliteDB = m_pGameCore->m_pSqliteDB = new Sqlite();

    while(1)
    {
        if(!LoadDatabase())
            return false;

        int ret = CheckConfig();
        if(ret > 0)
            continue;
        else if(ret < 0)
            return false;


        if(m_mapGameConfig.value("LoginUserPass", QString("")).toString().isEmpty())
        {
            m_mapGameConfig["RememberPassword"] = false;
        }
        else
            m_mapGameConfig["RememberPassword"] = true;


        SaveConfigToDb("RunTime", QString::number(m_mapGameConfig["RunTime"].toInt() + 1));
        //SaveConfigToDb("111","333");
        //DeleteConfigToDb("111");
        break;
    }

//读取配置(文件)
    m_ConfigFile.readConfigFile(m_mapGameConfig);
    //qDebug() << "m_ConfigFile" << m_ConfigFile.configHash;

    /*
    if(m_mapGameConfig.contains(key))
    {
        m_mapGameConfig[key] = value;
    }*/

//配置设置
    m_pInfoSocket->m_strIP = m_mapGameConfig.value("ServerIP", QVariant::fromValue(QString("pets.leamus.cn"))).toString();
    m_pInfoSocket->m_unPort = m_mapGameConfig.value("ServerPort", QVariant::fromValue(8860)).toInt();
    m_pGameCore->m_pGameModel->m_nGameRandom = m_mapGameConfig.value("Random", QVariant::fromValue(-1)).toInt();

    qDebug() << m_pInfoSocket->m_strIP << m_pInfoSocket->m_unPort;
    //qDebug() << "config" << config.configHash;


//UserInfo:
    connect(m_pUserInfo,&UserInfo::s_SendCodeDataToServer,this,[=](TcpSocket* pSocket,QByteArray ba)
    {
        //qDebug() << "数据长度:" << ba.length();
        NetLog(ba,true);
        pSocket->SendWithSafe(ba);
    });




//socket信号

    //Socket已连接
    connect(m_pInfoSocket,&TcpSocket::s_connected,this,[=]()
    {
        //if(m_LoginInfo.m_ClientStatus == UserInfo::Client_IsLoginingInfoServer ||
        //    m_LoginInfo.m_ClientStatus == UserInfo::Client_IsRegisteringInfoServer)

        //m_pUserInfo->send();
        //m_pUserInfo->m_pInfoSocket->sendCache();
        //m_pInfoSocket->send(false);
    });

    //Socket已连接
    connect(m_pGameSocket,&TcpSocket::s_connected,this,[=]()
    {
        //m_pUserInfo->m_pGameSocket->clearData();
        //m_pGameSocket->send(false);

        m_nDisconnectCode = -1;
    });


    //连接主机错误
    connect(m_pInfoSocket,&TcpSocket::s_error,this,[=](QAbstractSocket::SocketError socketError, TcpSocket* pTcpSocket)
    {
        m_pInfoSocket->clearAll();

        
        switch (socketError) {
        case QAbstractSocket::RemoteHostClosedError:
            break;
        case QAbstractSocket::HostNotFoundError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("没有发现服务器"));
            break;
        case QAbstractSocket::ConnectionRefusedError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("服务器拒绝链接"));
            break;
        case QAbstractSocket::NetworkError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("网络不可用"));
            break;
        default:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("网络故障:%1(%2)")
                                     .arg(pTcpSocket->errorString()) //为最后一次发生的错误返回一个用户可读的出错信息。
                                     .arg(socketError));
        }

        emit m_pUserInfo->s_loginStatus(-100);
    });

    //连接主机错误
    connect(m_pGameSocket,&TcpSocket::s_error,this,[=](QAbstractSocket::SocketError socketError, TcpSocket* pTcpSocket)
    {
        m_pGameSocket->clearAll();


        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedInfoServer;

        switch (socketError) {
        case QAbstractSocket::RemoteHostClosedError:
            break;
        case QAbstractSocket::HostNotFoundError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("没有发现服务器"));
            break;
        case QAbstractSocket::ConnectionRefusedError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("服务器拒绝链接"));
            break;
        case QAbstractSocket::NetworkError:
            QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("网络不可用"));
            break;
        default:
            break;
            /*QMessageBox::information(nullptr, tr("网络错误"),
                                     tr("网络故障:%1(%2)")
                                     .arg(pTcpSocket->errorString() //为最后一次发生的错误返回一个用户可读的出错信息。
                                     .arg(socketError)));
                                     */
        }
        emit s_qml_GameDisconnected(m_nDisconnectCode);



        QMap<qint32, QJSValue>::iterator ii;
        for (ii = m_mapSetGameDataToNetDBFunctionCache.begin(); ii != m_mapSetGameDataToNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_SetGameDataToNetDB(-1, -1, -1, false, *ii);
        for (ii = m_mapGetGameDataToNetDBFunctionCache.begin(); ii != m_mapGetGameDataToNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_GetGameDataToNetDB(QVariantList(), -1, -1, -1, false, *ii);
        for (ii = m_mapDeleteGameDataToNetDBFunctionCache.begin(); ii != m_mapDeleteGameDataToNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_DeleteGameDataToNetDB(-1, -1, -1, false, *ii);
        for (ii = m_mapInsertGameDataToNetDBFunctionCache.begin(); ii != m_mapInsertGameDataToNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_InsertGameDataToNetDB(-1, -1, -1, false, *ii);
        for (ii = m_mapUpdateGameDataToNetDBFunctionCache.begin(); ii != m_mapUpdateGameDataToNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_UpdateGameDataToNetDB(-1, -1, -1, false, *ii);
        for (ii = m_mapQueryNetDBFunctionCache.begin(); ii != m_mapQueryNetDBFunctionCache.end(); ++ii)
            if(ii->isCallable())
                emit s_NetDBQuery(-1, -1, -1, QVariantList(), -1, false, *ii);

        m_mapSetGameDataToNetDBFunctionCache.clear();
        m_mapGetGameDataToNetDBFunctionCache.clear();
        m_mapDeleteGameDataToNetDBFunctionCache.clear();
        m_mapInsertGameDataToNetDBFunctionCache.clear();
        m_mapUpdateGameDataToNetDBFunctionCache.clear();
        m_mapQueryNetDBFunctionCache.clear();



        //emit s_ConnectServerErr(10,m_pUserInfo->m_pInfoSocket->error());
    });


    //断开
    connect(m_pInfoSocket,&TcpSocket::s_disconnected,this,[=]()
    {
        m_pInfoSocket->clearAll();
    });

    //断开
    connect(m_pGameSocket,&TcpSocket::s_disconnected,this,[=]()
    {
        m_pGameSocket->clearAll();


        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedInfoServer;


        emit s_qml_GameDisconnected(m_nDisconnectCode);


        m_nOldSocketID = m_pGameSocket->m_nSocketID;

        if(m_pGameSocket->clientGroupStatus() != GroupStatus_Playing)
        {
            m_pGameSocket->clearGroupInfo();
        }

        if(m_pGameCore->m_pGameModel->m_bNetPlay == true && m_pGameCore->m_pGameModel->isRunning())    //网络游戏时断开
        {
            //m_pGameCore->m_bTerminateGame = true;
            m_pGameCore->sl_OverGame(GameModel::Game_Status_Terminated, -3);
            //m_pGameCore->TerminateGame(GameModel::Game_Status_Terminated, -3);

            //QMessageBox::information(nullptr,"错误","游戏服务器网络断开!");

            //emit s_qml_ChangeAllWindowVisible(2);
        }
        else
        {
            //m_pGameCore->m_bTerminateGame = true;
            m_pGameCore->sl_OverGame(GameModel::Game_Status_Terminated, -3);
            //m_pGameCore->TerminateGame(GameModel::Game_Status_Terminated, -3);

            //QMessageBox::information(nullptr,"错误","游戏服务器网络断开!");

            //emit s_qml_ChangeAllWindowVisible(2);
        }
    });


    //InfoSocket数据处理
    connect(m_pInfoSocket,&TcpSocket::s_readyRead,this,&GameManager::OnInfoReadyRead);

    //GameSocket数据处理
    connect(m_pGameSocket,&TcpSocket::s_readyRead,this,&GameManager::OnInfoReadyRead);//OnGameReadyRead



    //游戏发送s_SendDataToServer信号
    connect(m_pGameCore,&Game::s_SendDataToServer,this,[=](QByteArray data, quint8 outControlbyte)
    {
        NetLog(data,false);
        m_pGameCore->m_pGameSocket->send(data, outControlbyte, false);
    });


    //游戏窗口
    connect(m_pGameCore->m_pGameModel,&GameModel::s_GameOver,this,[=](GameModel::_GameStatus status, qint32 code)
    {
        sl_GameOver(status, code);
    });

    //游戏前的初始化
    connect(m_pGameCore->m_pGameModel,&GameModel::s_GameInitFinished,this,[=]()
    {
        m_mapDisconnectClientInfo.clear();
        m_pGameSocket->m_ClientGroupInfo.m_unFrameIndex = 0;


        //qDebug() << "[GameManager]s_GameInitFinished:m_pGameCore->m_bNetPlay:" << m_pGameCore->m_bNetPlay;
        if(m_pGameCore->m_pGameModel->m_bNetPlay == true)
        {
            m_pGameCore->m_pGameSocket->sendData()
                    << static_cast<qint16>(GAME_DATA)
                    << static_cast<qint16>(GAME_DATA_INITOVER)
                       //<< m_pUserInfo->m_GameServerUserInfo.unUserGameID
                       ;
            m_pGameCore->m_pGameSocket->send(TRANSMIT_GAME_TYPE, false);
            //qDebug() << "[GameManager]发送Init!";
        }
    });

    connect(m_pGameCore,&Game::s_Message,this,[=](QString msg)
    {
        qInfo() << msg;
    });
    connect(m_pGameCore,&Game::s_Debug,this,[=](QString msg)
    {
        qDebug() << msg;
    });
    connect(m_pGameCore,&Game::s_Critical,this,[=](QString msg)
    {
        qCritical() << msg;
    });



//版本检查
    connect(&m_VersionCheck, &VersionCheck::s_JsonParseResult, this, [=]() {

        qDebug() << "[GameManager]VersionCheck:"
                 << m_VersionCheck.m_nForceVersion
                 << m_VersionCheck.m_nLastestVersion
                 << m_VersionCheck.m_strUpdateURL
                 << m_mapGameConfig.value("Version").toInt()
                 << _Game_Version_;

        //如果出错,则强制升级
        if(m_VersionCheck.m_nForceVersion < 0 || m_VersionCheck.m_nLastestVersion < 0)
        {
            emit s_qml_UpdateInfo(m_VersionCheck.m_strUpdateURL, -2);
            return;
        }

        //如果 强制升级 > 目前版本,则强制升级
        if(m_VersionCheck.m_nForceVersion > _Game_Version_)
        {
            emit s_qml_UpdateInfo(m_VersionCheck.m_strUpdateURL, 2);
            return;
        }

        //如果 最新版本 < 目前版本,则出错
        if(m_VersionCheck.m_nLastestVersion < _Game_Version_)
        {
            emit s_qml_UpdateInfo(m_VersionCheck.m_strUpdateURL, -1);
            return;
        }


//安卓还需检测 数据库版本!
#if defined(Q_OS_ANDROID)
        //如果 数据库版本错误,或 数据库版本 < 强制升级版本,则重新复制数据库文件
        if(!m_mapGameConfig.contains("Version")
                || (m_VersionCheck.m_nLastestVersion < m_mapGameConfig.value("Version").toInt())    //版本错误
                || m_VersionCheck.m_nForceVersion > m_mapGameConfig.value("Version").toInt()    //强制更新
                )
        {
            m_pSqliteDB->close();
            QFile::remove(FIXLOCALPATH_W("Game.dat"));
            copyFileAndSetPermissions(("Game.dat"), QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner);
            QFile::remove(FIXLOCALPATH_W("Config.cfg"));
            copyFileAndSetPermissions(("Config.cfg"), QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner);
            if(!LoadDatabase())
            {
                emit s_qml_Message(_T("数据库错误，请重新进入游戏！"), 2);
                return;
            }
            SaveConfigToDb("LoginUserName",m_pUserInfo->userName());
            if(true == m_mapGameConfig["RememberPassword"])
                SaveConfigToDb("LoginUserPass",m_pUserInfo->m_LoginInfo.m_strPassword);
            else
                SaveConfigToDb("LoginUserPass","");

            SaveConfigToDb("RunTime", m_mapGameConfig["RunTime"].toString());
        }
#endif

        //如果 最新 > 当前,且最新版本没有被忽略,则建议升级
        if(m_VersionCheck.m_nLastestVersion > _Game_Version_
                && m_VersionCheck.m_nLastestVersion > m_mapGameConfig.value("IgnoreVersion").toInt())
        {
            emit s_qml_UpdateInfo(m_VersionCheck.m_strUpdateURL, 1);
        }
        else
            emit s_qml_UpdateInfo("", 0);


        //显示广播
        if(m_VersionCheck.m_nBroadcastVersion > m_mapGameConfig.value("BroadcastVersion").toInt())
        {
            emit s_qml_Message(m_VersionCheck.m_strBroadcastContent, 0);
            SaveConfigToDb("BroadcastVersion", QString::number(m_VersionCheck.m_nBroadcastVersion));
        }
    });

    connect(&m_VersionCheck, &VersionCheck::s_Critical, this, [=](QString msg) {
        qCritical() << _T("[!GameManager]VersionCheck ERROR:%1").arg(msg);
        emit s_qml_UpdateInfo("http://pets.leamus.cn/download", -3);
    });






//QML
    m_pAppQmlEngine = new QQmlApplicationEngine(this);
    m_pAppQmlEngine->addImportPath("QML");
    m_pAppQmlEngine->addImportPath("qrc:/QML");     //我自己的QML库
    m_pAppQmlEngine->addImportPath(getExternalDataPath() + QDir::separator() + "QML");
#if defined(Q_OS_ANDROID)
    m_pAppQmlEngine->addImportPath("assets:/QML");
#endif

    m_pAppQmlEngine->rootContext()->setContextProperty("GameManager",this);
    m_pAppQmlEngine->rootContext()->setContextProperty("GameCore",getGameCore());
    m_pAppQmlEngine->rootContext()->setContextProperty("UserInfo",getUserInfo());
    m_pAppQmlEngine->rootContext()->setContextProperty("Platform",getPlatform());
    //m_pAppQmlEngine->rootContext()->setContextProperty("WordLib",pWordLib);
    //m_pAppQmlEngine->rootContext()->setContextObject(&gamedata);

    //qDebug() << "!!!!!!";
    //qDebug() << FIXPATH(QML/Login/login.qml);
    //qDebug() << FIXPATH(QML/Register/Register.qml);

    //m_pAppQmlEngine->load("file:QML/main.qml");
    //m_pAppQmlEngine->load(QUrl(QStringLiteral("file:QML/main.qml")));

#if defined(Q_OS_WIN32)   //win
#ifdef QT_NO_DEBUG
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#else
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
    //m_pAppQmlEngine->load(FIXLOCALPATH_R("QML/main.qml"));
#endif
#elif defined(Q_OS_MACOS)   //macos
#ifdef QT_NO_DEBUG
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#else
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#endif
#elif defined(Q_OS_ANDROID)   //linux
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#elif defined(Q_OS_LINUX)   //linux
#ifdef QT_NO_DEBUG
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#else
    m_pAppQmlEngine->load(FIXLOCALPATH_R("QML/main.qml"));
#endif
#else
    m_pAppQmlEngine->load(FIXRESOURCEURL_R("QML/main.qml"));
#endif

    //m_pAppQmlEngine->load(FIXPATH(QML/main.qml));

    //m_pAppQmlEngine->load(FIXPATH(QML/Login/login.qml));
    //m_pAppQmlEngine->load(FIXPATH(QML/Register/Register.qml));
    //m_pAppQmlEngine->load(FIXPATH(QML/GameCenter/GameCenter.qml));
    //m_pAppQmlEngine->load(FIXPATH(QML/debugWindow.qml));
    //m_pAppQmlEngine->load(QUrl(QStringLiteral("QML/debugWindow.qml")));

    QList<QObject*> oList = m_pAppQmlEngine->rootObjects();
    if (m_pAppQmlEngine->rootObjects().isEmpty()) {
        qCritical() << "[!GameManager]读取QML文件ERROR!";
        return false;// -1;
    }
    m_pGameWindow = qobject_cast<QQuickWindow*>(oList.at(0));
    //m_pGameWindow = dynamic_cast<QQuickWindow*>(oList.at(0));
    //m_pGameWindow->activateWindow();
    //m_pGameWindow->raise();
/*
    QQuickView *pQuickView = new QQuickView;
    pQuickView->setColor(QColor(Qt::transparent));
    pQuickView->rootContext()->setContextProperty("GameManager",this);
    pQuickView->rootContext()->setContextProperty("GameCore",gameCore());
    pQuickView->rootContext()->setContextProperty("UserInfo",userInfo());
    pQuickView->setSource(QUrl("qrc:/QML/main.qml"));
    pQuickView->show();
*/
    //pQuickView->setStyleSheet("background:transparent;");
    //pQuickView->setAttribute(Qt::WA_TranslucentBackground);
    //pQuickView->setWindowFlags(Qt::FramelessWindowHint);
    //pQuickView->set

    //pLoginWindow = dynamic_cast<QQuickWindow*>(oList.at(0));
    //pRegisterWindow = dynamic_cast<QQuickWindow*>(oList.at(1));
    //pGameCenterWindow = dynamic_cast<QQuickWindow*>(oList.at(2));
    //pDebugWindow = dynamic_cast<QQuickWindow*>(oList.at(1));

    //pRegisterWindow->hide();
    //pGameCenterWindow->hide();
    //m_pGameWindow->hide();


    //m_pAppQmlEngine->se
    //m_pGameWindow->setColor(QColor(Qt::transparent));
    //m_pGameWindow->setMask(QRegion(QRect(0, 0, 10, 10)));
    //m_pGameWindow->setAttribute(Qt::WA_TranslucentBackground);
    //m_pGameWindow->setStyleSheet("background:transparent;");

    //oList.first()->objectName()



    //pLoginBox->setWindowTitle("登录");
    //pRegister->setWindowTitle("注册");
    //pCenter->setWindowTitle("游戏大厅");
    //m_pGameWindow->setWindowTitle("英语杀");
    //w.setMaximumSize(800,400);
    //w.setMinimumSize(800,400);
    //w.setFixedSize(800,400);
    //w.setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowFullscreenButtonHint|Qt::WindowMinimizeButtonHint);
    //w.setFixedSize(w.width(),w.height());


    //pLoginBox->show();
    //w.showFullScreen();
    //a.installEventFilter(new EventFilter);








    //单人游戏
    //connect(m_pGameWindow,SIGNAL(s_StartGame(int,int,int,int))
    //        ,this,SLOT(sl_qml_SinglePlay(int,int,int,int)));

    //登录
    //connect(m_pGameWindow,SIGNAL(s_login(QVariant))
    //        ,m_pUserInfo,SLOT(userLogin(QVariant)));

    //注册
    //connect(m_pGameWindow,SIGNAL(s_RegUser(QVariant))
    //        ,m_pUserInfo,SLOT(userReg(QVariant)));

    //选择服务器
    //connect(m_pGameWindow,SIGNAL(s_RegUser(QVariant))
    //        ,m_pUserInfo,SLOT(userReg(QVariant)));



    //检测升级
    m_VersionCheck.m_strJsonURL = "http://pets.leamus.cn/GameInfo.json";
    m_VersionCheck.checkVersion();



    lmsSrand(-1);
    lms_DefaultRandom(0, 1, -1);



    //初始化
    QVariant v;
    QMetaObject::invokeMethod(m_pGameWindow,"initOnce"
                              ,Qt::AutoConnection
                              //,Q_RETURN_ARG(QVariant,v)
                              ,Q_ARG(QVariant,v)
                              );


    m_pGameCore->InitOnce();


    return true;
}





int GameManager::SaveConfigToDb(QString key, QString value)
{
    if(!m_pSqliteDB->isValid())
        return -1;

    if(m_mapGameConfig.contains(key))
    {
        if(m_mapGameConfig.value(key).toString() == value)
            return 0;

        m_mapGameConfig[key] = value;

        QString sql = QString("UPDATE GameConfig SET Value='%1' WHERE Key='%2'").arg(value).arg(key);
        QSqlQuery query(*m_pSqliteDB->getDB());  //查询

        if(!query.exec(sql))
        {
            qCritical() << ("[!GameManager]UPDATE GameConfig ERROR:") << query.lastError().text() << key << value;
            qCritical() << sql;
            return -2;
        }
        int ret = query.numRowsAffected();
        query.finish();
        qDebug() << "UPDATE numRowsAffected:" << ret << key << m_mapGameConfig[key];
        return ret;
    }
    else
    {
        m_mapGameConfig[key] = value;

        QString sql = QString("INSERT INTO GameConfig(Key,Value) VALUES('%1','%2')").arg(key).arg(value);
        QSqlQuery query(*m_pSqliteDB->getDB());  //查询

        if(!query.exec(sql))
        {
            qCritical() << ("[!GameManager]INSERT GameConfig ERROR!") << query.lastError().text() << key << value;
            qCritical() << sql;
            return -3;
        }
        int ret = query.numRowsAffected();
        query.finish();
        qDebug() << "INSERT numRowsAffected:" << ret << key << m_mapGameConfig[key];
        return ret;
    }
}

int GameManager::DeleteConfigToDb(QString key)
{
    if(!m_pSqliteDB->isValid())
        return -1;

    if(m_mapGameConfig.contains(key))
    {
        m_mapGameConfig.remove(key);

        QString sql = QString("DELETE FROM GameConfig WHERE Key='%1'").arg(key);
        QSqlQuery query(*m_pSqliteDB->getDB());  //查询

        if(!query.exec(sql))
        {
            qCritical() << ("[!GameManager]DELETE GameConfig ERROR:") << query.lastError().text() << key;
            qCritical() << sql;
            return -2;
        }
        int ret = query.numRowsAffected();
        query.finish();
        qDebug() << "DELETE numRowsAffected:" << ret;
        return ret;
    }
    return 0;
}

int GameManager::LoadConfigFromDb()
{
    if(!m_pSqliteDB->isValid())
        return -1;

    QString sql = "SELECT * FROM GameConfig";
    QSqlQuery query(*m_pSqliteDB->getDB());  //查询


    if(!query.exec(sql))
    {
        qCritical() << ("[!GameManager]Query GameConfig ERROR!") << query.lastError().text();
        qCritical() << sql;
        return -2;
    }

    m_mapGameConfig.clear();
    int ret = query.numRowsAffected();

    while(query.next())
    {
        m_mapGameConfig[query.value("Key").toString()] = query.value("Value");
    }
    query.finish();
    qDebug() << "读取GameConfig结束:"<<m_mapGameConfig.count();
    return ret;
}



bool GameManager::LoadDatabase()
{
    if(!m_pSqliteDB->connectDB(FIXLOCALPATH_W("Game.dat"),"Pleafles@Leamus"))
    {
        QMessageBox::critical(nullptr,"深林孤鹰提示","数据库错误!");
        return false;
    }

    //m_pUserInfo->m_pTempDB = pWordLib->getDB();
    if(LoadConfigFromDb() < 0)
    {
        qCritical() << "[!GameManager]LoadConfigFromDb ERROR!";
        return false;
    }
    return true;
}

int GameManager::CheckConfig()
{
    if(!m_mapGameConfig.contains("Version"))
    {
        SaveConfigToDb("Version", QString::number(1));
    }

    int version = m_mapGameConfig["Version"].toInt();
    if(version == 1)
    {

    }
    if(version == 2)
    {

    }
    if(version == 3)
    {

    }
    if(version == 4)
    {
/*
#if defined(Q_OS_ANDROID)
        m_pSqliteDB->close();
        QFile::remove("Game.dat");
        copyFileAndSetPermissions("Game.dat", QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner);
        return 1;
#endif
*/
    }

    /*
    switch(m_mapGameConfig["Version"].toInt())
    {
        case 1:
            break;
        case 2:
            break;
        default:
            break;
    }*/
    return 0;
}




void GameManager::sl_StartGame(bool netPlay, bool isStarted)
{
    emit s_qml_DebugMsg(tr("主线程Manager随机数种子:%1").arg(lmsSrand(-1)));

    if(m_pGameSocket->getGroupIndex() == -1)
        m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Watching);
    else
        m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Playing);
    m_pGameCore->m_pGameModel->m_bNetPlay = netPlay;

    //m_pGameCore->TerminateGame();

    if(netPlay) //联网游戏
    {
        m_pGameCore->m_pGameModel->m_bRunAtServer = false;
        m_pGameCore->m_pGameModel->m_bLogicalMaster = false;
        m_pGameCore->m_pGameModel->m_eGameType = GameModel::Game_Type_1;
        //m_pGameCore->m_Producer.init();
        //m_pGameCore->isMaster = false;

    }
    else        //单人游戏
    {
        sl_Server_StartGame();

        m_pGameCore->m_pGameModel->m_bRunAtServer = false;
        m_pGameCore->m_pGameModel->m_bLogicalMaster = true;
        m_pGameCore->m_pGameModel->m_eGameType = GameModel::Game_Type_1;
        //m_pGameCore->playerCount = playerCount;
        //m_pGameCore->isMaster = true;
        //m_pGameCore->iMyID = rand() % playerCount;


        /*
        //初始化所有Player
        for(int i = 0; i < playerCount; i++)
        {
            m_pGameCore->m_arrayPlayer[i].m_nDuiWu = i;

            if(i == m_pGameCore->m_nMyID)
            {
                m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_Self;
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname = m_pUserInfo->nickName();
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nSex = m_pUserInfo->sex();
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nServerID = m_pUserInfo->serverID();
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nGradeID = m_pUserInfo->gradeID();
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nScore = m_pUserInfo->scoreCount();

            }
            else
            {
                m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_AI;
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname = "【小艾】";
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nSex = Random(0,2);
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nServerID = -1;
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nGradeID = -1;
                m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nScore = Random(0, 100000000);
            }
        }
        */

    }

    m_pGameCore->GameInit();

    //m_pGameSocket->clearData();
    //emit s_qml_GameStart();
    m_pGameCore->GameStart(isStarted);
}

void GameManager::sl_GameOver(GameModel::_GameStatus status, qint32 code)
{
    if(m_pGameCore->m_pGameModel->m_bNetPlay == true)
    {
        QMap<qint32, QObject*>::const_iterator ii;
        for (ii = m_mapPlayerInGroupInfo.constBegin(); ii != m_mapPlayerInGroupInfo.constEnd(); ++ii)
        {
            PlayerInfo *playerinfo = qobject_cast<PlayerInfo*>(*ii);
            if(playerinfo->getIndex() == -1)
                playerinfo->m_ClientGroupStatus = _ClientGroupStatus::GroupStatus_ReadyToWatch;
            else
            {
                //if(playerinfo->isGroupMaster())
                //    playerinfo->m_ClientGroupStatus = _ClientGroupStatus::GroupStatus_Readying;
                //else
                    playerinfo->m_ClientGroupStatus = _ClientGroupStatus::GroupStatus_Waiting;
            }
        }

        if(m_pGameSocket->getGroupIndex() == -1)
            m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_ReadyToWatch);
        else
        {
            //if(m_pGameSocket->isGroupMaster())
            //    m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Readying);
            //else
                m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Waiting);
        }
        qDebug() << "联网游戏结束!";
        /*
        m_pGameCore->m_pGameSocket->sendData()
                << (qint16)GAME_DATA << (qint16)GAME_DATA_GAMEOVER;
        m_pGameCore->m_pGameSocket->send();
        */
    }
    else
    {
        m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Nothing);
    }


    qint16 achieve = 0;
    //退出类型
    switch(status)
    {
    case GameModel::Game_Status_Terminated:
        m_pGameSocket->sendData()
                << static_cast<qint16>(GAME_DATA)
                << static_cast<qint16>(GAME_DATA_GAMEOVER)
                << static_cast<qint16>(status)
                << code
                   ;
        m_pGameSocket->send(TRANSMIT_GAME_TYPE, false);
        achieve = 3;

        //m_pUserInfo->m_GameServerUserInfo.scoreAdd = -100;
        qDebug() << "[GameManager]强制退出:" << status << code;
        break;

    case GameModel::Game_Status_GameOver:
        //if(m_pGameCore->m_pGameModel->m_bNetPlay == false)     //单人游戏还得发送游戏结束
        {
            m_pGameSocket->sendData()
                    << static_cast<qint16>(GAME_DATA)
                    << static_cast<qint16>(GAME_DATA_GAMEOVER)
                    << static_cast<qint16>(status)
                    << code
                       ;
            m_pGameSocket->send(TRANSMIT_GAME_TYPE, false);
        }
        achieve = m_pGameCore->m_pGameModel->isWin() ? 1 : 2;

        //m_pUserInfo->m_GameServerUserInfo.scoreAdd = m_pSqliteDB->totalScore() + (m_pGameCore->isWin() ? 5 : 0);
        qDebug() << "[GameManager]正常退出:" << status << code;
        break;

    case GameModel::Game_Status_Exit:
        achieve = 4;

        //m_pUserInfo->m_GameServerUserInfo.scoreAdd = m_pSqliteDB->totalScore();
        qDebug() << "[GameManager]指令退出:" << status << code;
        break;

    case GameModel::Game_Status_ERROR:
    default:
        m_pGameSocket->sendData()
                << static_cast<qint16>(GAME_DATA)
                << static_cast<qint16>(GAME_DATA_GAMEOVER)
                << static_cast<qint16>(status)
                << code
                   ;
        m_pGameSocket->send(TRANSMIT_GAME_TYPE, false);
        achieve = 5;

        //m_pUserInfo->m_GameServerUserInfo.scoreAdd = m_pSqliteDB->totalScore();
        qCritical() << "[!GameManager]游戏退出ERROR:"<<status<<code;
    }
    /*
    else if(m_pGameCore->isMaster == true)
    {
        if(m_pGameCore->m_bNetPlay == true)
        {
            m_pGameCore->m_pGameSocket->sendData()
                    << (qint16)GAME_DATA
                    << (qint16)GAME_DATA_GAMEOVER;
            m_pGameCore->m_pGameSocket->send();
        }
    }*/


    //m_pUserInfo->updateGameUserScoreInfoLocal();
    /*qint32 totalScore = m_pGameCore->totalScore();
    //if(totalScore != 0)
        qDebug() << "更新增加金币:" << totalScore << achieve;
    //else
    //    qDebug() << "不更新金币";

    m_pUserInfo->updateGameUserScoreInfo(achieve, totalScore);*/


    m_mapDisconnectClientInfo.clear();



    emit s_qml_GameOver(status, code);

    //QVariant v;
    //QMetaObject::invokeMethod(m_pGameWindow,"gameOver"
    //                          ,Q_RETURN_ARG(QVariant,v)
    //                          ,Q_ARG(QVariant,status));
}



void GameManager::sl_Server_CreateGroup(qint32 playerMaxCount, qint32 playerWatchingMaxCount, const QString& password, qint32 groupType, QVariant vData)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_CREATE
                              << (qint32)playerMaxCount
                              << (qint32)playerWatchingMaxCount
                              << password
                              << groupType
                              << vData
                               ;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_UpdateGroup(bool lock, bool autoClose)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_UPDATE
                              << lock
                              << autoClose
                               ;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_ExitGroup()
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_EXITGROUP;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_CloseGroup(qint32 groupID)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_CLOSE
                              << groupID;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

//gid:0为随机加入;password:密码
void GameManager::sl_Server_JoinGroup(qint32 gid, QString password, bool forceJoin, qint32 joinType, qint32 groupType)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_JOINGROUP
                              << gid << password << forceJoin << joinType << groupType;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_GetReady(qint16 duiWu)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_GETREADY
                              << (qint16)duiWu;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_Kick(qint32 socketID)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_KICK
                              << socketID;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_SendMessage(QString msg, qint16 type)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_MESSAGE
                              << m_pUserInfo->m_GameServerUserInfo.unUserGameID << (qint16)type << msg
                               ;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_qml_ReJoinRunningGroup()
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_REJOINRUNNINGGROUP
                              << m_pGameSocket->getGroupID() << m_pGameSocket->getGroupIndex() << m_nOldSocketID;
                               ;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_qml_ReleaseGroupIndex(quint32 oldUserGameID, qint32 oldGroupIndex)
{
    m_pGameSocket->sendData() << (qint16)GAME_SERVER_REQUEST
                              << (qint16)GAME_SERVER_GROUP
                              << (qint16)GAME_SERVER_GROUP_RELEASEGROUPINDEX
                              << oldGroupIndex << oldUserGameID;
                               ;
    m_pGameSocket->send(TRANSMIT_GROUP_TYPE, false);
}

void GameManager::sl_Server_StartGame()
{
    m_pGameSocket->sendData() << (qint16)GAME_DATA
                              << (qint16)GAME_DATA_STARTGAME
                              << (qint16)0;
    m_pGameSocket->send(TRANSMIT_GAME_TYPE, false);
}




bool GameManager::sl_qml_FileExists(const QString &strPathFile)
{
    return QFileInfo(strPathFile).exists();
}

QString GameManager::sl_qml_ReadFile(const QString &strPathFile)
{
    if(!sl_qml_FileExists(strPathFile))
        return "";

    QFile file(strPathFile);
    file.open(QIODevice::ReadOnly);
    QTextStream ds(&file);
    QString strData = ds.readAll();
    //ds << QThread::currentThreadId();

    file.flush();
    file.close();

    return strData;
}

int GameManager::sl_qml_WriteFile(const QString &strData, const QString &strPathFile, int writeType)
{
    QDir dir(QFileInfo(strPathFile).absolutePath());
    if(!dir.exists())    /**< 如果目标目录不存在，则进行创建 */
        if(!dir.mkpath(dir.absolutePath()))
            return -1;

    QFile file(strPathFile);
    if(writeType == 0)
        file.open(QIODevice::WriteOnly);
    else
        file.open(QIODevice::WriteOnly | QIODevice::Append);
    QTextStream ds(&file);
    ds << strData;
    //ds << QThread::currentThreadId();

    file.flush();
    file.close();

    return 0;
}

int GameManager::sl_qml_DeleteFile(const QString &strPathFile)
{
    if(!sl_qml_FileExists(strPathFile))
        return 1;

    if(QFile::remove(strPathFile))
        return 0;

    return -1;
}




void GameManager::OnInfoReadyRead(TcpSocket* sock)
{
    qint16 data;

    //uint datalen = sock->recievedDataSize();
    //if(m_pGameCore->m_bMaster)
    //    qDebug() << "主机客户端接收数据大小:" << datalen;
    //else
    //    qDebug() << "副机客户端接收数据大小:" << datalen;


    //QDataStream dsData(baData);
    //while(!sock->recievedData().atEnd())
    //if(!sock->recievedData().atEnd())     //不能判断数据是否空,因为有些没有数据,比如8d类型
    {
        switch(sock->m_ucInControlByte)
        {
        case TRANSMIT_SOCKET_ID:
            return;
        case TRANSMIT_CODE_RECIEVED:
            return;
        case TRANSMIT_CODE_DATA:
            break;

        default:
            break;
        }


        sock->recievedData() >> data;
        qDebug() << "数据类型1:" << data;
        switch(data)
        {
        case INFO_SERVER_RESPONSE:
            {
                sock->recievedData() >> data;
                switch(data)
                {
                case INFO_SERVER_CLIENT:
                    {
                        sock->recievedData() >> data;
                        switch(data)
                        {
                        case INFO_SERVER_CLIENT_LOGIN:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case INFO_SERVER_CLIENT_LOGIN_SUCCESS:
                                    {
                                        sock->recievedData() >> m_pUserInfo->m_LoginInfo.m_unID;// >> m_pUserInfo->m_LoginInfo.m_nSocketID;

                                        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedInfoServer;

                                        SaveConfigToDb("LoginUserName",m_pUserInfo->userName());
                                        if(true == m_mapGameConfig["RememberPassword"])
                                            SaveConfigToDb("LoginUserPass",m_pUserInfo->m_LoginInfo.m_strPassword);
                                        else
                                            SaveConfigToDb("LoginUserPass","");

                                        qDebug() << "[InfoServer]登录成功:" << m_pUserInfo->m_LoginInfo.m_unID;// << m_pUserInfo->m_LoginInfo.m_nSocketID;
                                        emit m_pUserInfo->s_loginStatus(0);
                                        //m_pUserInfo->loadGameServersInfo();
                                    }
                                    break;
                                case INFO_SERVER_CLIENT_LOGIN_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        //m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginOut;
                                        switch(data)
                                        {
                                        case -1:
                                            //QMessageBox::information(pLoginBox,tr("登录失败"),tr("用户名或密码错误"));
                                            break;
                                        case -2:
                                            //QMessageBox::information(pLoginBox,tr("登录失败"),tr("已经在其他地方登录"));
                                            break;
                                        default:
                                            //QMessageBox::information(pLoginBox,tr("登录失败"),tr("未知错误"));
                                            break;
                                        }
                                        emit m_pUserInfo->s_loginStatus(data);

                                        //pLoginBox->setStatus(0);
                                    }
                                    break;
                                }
                            }
                            break;

                        case INFO_SERVER_CLIENT_REGISTER:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case INFO_SERVER_CLIENT_REGISTER_SUCCESS:
                                    {
                                        sock->recievedData() >> m_pUserInfo->m_LoginInfo.m_unID;    // >> m_pUserInfo->m_LoginInfo.m_nSocketID;
                                        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedInfoServer;
                                        emit m_pUserInfo->s_regStatus(0);
                                        //QMessageBox::information(pRegister,tr("注册成功"),tr("注册成功"));
                                        //pRegister->hide();
                                        //pCenter->show();
                                    }
                                    break;
                                case INFO_SERVER_CLIENT_REGISTER_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        //m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedInfoServer;
                                        //if(data == 1)
                                            emit m_pUserInfo->s_regStatus(data);
                                        //QMessageBox::information(pRegister,tr("注册失败"),tr("注册失败"));
                                        //pRegister->setStatus(0);
                                    }
                                    break;
                                }
                            }
                            break;

                        case INFO_SERVER_CLIENT_SERVERINFO:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case INFO_SERVER_CLIENT_SERVERINFO_SUCCESS:
                                    {
                                        m_pUserInfo->clearGameServersInfo();
                                        sock->recievedData() >> data;
                                        qDebug() << "[InfoServer]获取游戏服务器列表成功:" << data;
                                        while(data)
                                        {
                                            _GameServerInfo *pGameServerInfo = new _GameServerInfo;
                                            sock->recievedData() >> pGameServerInfo->m_nServerID;
                                            sock->recievedData() >> pGameServerInfo->m_strName;
                                            sock->recievedData() >> pGameServerInfo->m_strIP;
                                            sock->recievedData() >> pGameServerInfo->m_unPort;
                                            sock->recievedData() >> pGameServerInfo->m_strKey;
                                            m_pUserInfo->m_mapGameServerInfo.insert(QString::number(pGameServerInfo->m_nServerID)
                                                                                  , QVariant::fromValue(pGameServerInfo));
                                            //m_GameServerInfoList.append(QVariant::fromValue<_GameServerInfo*>(pGameInfo));
                                            //m_GameServerInfoList.insert(query.value("ID").toString(),QVariant::fromValue<ClassInfo*>(cInfo));
                                            data--;
                                        }
                                        m_pInfoSocket->close();

                                        emit m_pUserInfo->s_gameServerInfoStatus(0);
                                    }
                                    break;
                                case INFO_SERVER_CLIENT_SERVERINFO_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!InfoServer]获取游戏服务器信息ERROR:" << data;
                                        m_pInfoSocket->close();

                                        emit m_pUserInfo->s_gameServerInfoStatus(data);
                                    }
                                    break;
                                }
                            }
                            break;

                        default:
                            qCritical() << ("[!GameManager]INFO_SERVER_CLIENT ERROR!");
                            break;
                        }
                    }
                    break;
                }
            }
            break;

        case GAME_SERVER_RESPONSE:
            {
                sock->recievedData() >> data;
                switch(data)
                {
                case GAME_SERVER_CLIENT:
                    {
                        sock->recievedData() >> data;
                        switch(data)
                        {
                        case GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO_SUCCESS:
                                    {
                                        sock->recievedData() >> m_pUserInfo->m_GameServerUserInfo.unUserGameID;

                                        qDebug() << "[GameManager]注册游戏用户信息成功:" << m_pUserInfo->m_GameServerUserInfo.unUserGameID;

                                        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedGameServer;
                                        //emit m_pUserInfo->s_choiceGameServerStatus(0);
                                        emit m_pUserInfo->s_regGameServerStatus(0);
                                    }
                                    break;
                                case GAME_SERVER_CLIENT_REGISTERGAMEUSERINFO_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        switch(data)
                                        {
                                        case 1:
                                            emit m_pUserInfo->s_regGameServerStatus(1);
                                            break;
                                        default:
                                            qCritical() << "[!GameManager]注册游戏用户信息ERROR:" << data;
                                            emit m_pUserInfo->s_regGameServerStatus(data);
                                        }

                                    }
                                    break;
                                default:
                                    //m_pUserInfo->s_regGameStatus(-1);
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_CLIENT_GAMEUSERINFO:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_CLIENT_GAMEUSERINFO_SUCCESS:
                                    {
                                        quint32 userGameID;
                                        QString nick;
                                        qint32 score;
                                        qint16 sex;
                                        sock->recievedData() >> userGameID;
                                        sock->recievedData() >> nick;
                                        sock->recievedData() >> sex;
                                        sock->recievedData() >> score;
                                        sock->recievedData() >> m_pUserInfo->m_GameServerUserInfo.vExtraData;

                                        //sock->recievedData() >> m_pUserInfo->m_GameServerUserInfo.nScoreYesterday;
                                        //sock->recievedData() >> m_pUserInfo->m_GameServerUserInfo.nScoreWeek;

                                        m_pUserInfo->m_GameServerUserInfo.unUserGameID = userGameID;
                                        m_pUserInfo->setNickName(nick);
                                        m_pUserInfo->setSex(sex);
                                        m_pUserInfo->setScoreCount(score);

                                        qDebug() << "[GameManager]获取游戏用户信息成功";

                                        m_pUserInfo->m_LoginInfo.m_ClientStatus = UserInfo::Client_IsLoginedGameServer;

                                        emit m_pUserInfo->s_loginGameServerStatus(0);

                                        if(userGameID <= 0)
                                            qCritical() << ("[!GameManager]获取GameUserID ERROR:" + QString::number(userGameID));
                                    }
                                    break;
                                case GAME_SERVER_CLIENT_GAMEUSERINFO_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        switch(data)
                                        {
                                        case 1: //需要注册
                                            emit m_pUserInfo->s_loginGameServerStatus(1);
                                            break;
                                        default:
                                            qCritical() << "[!GameManager]获取游戏用户信息ERROR:" << data;
                                            emit m_pUserInfo->s_loginGameServerStatus(data);
                                        }

                                    }
                                    break;
                                default:
                                    break;
                                }
                            }
                            break;



                        case GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET:
                            {
                                sock->recievedData() >> data;

                                switch(data)
                                {
                                case GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]SetClientShareExtraGameData Success";
                                        emit s_SetClientShareExtraGameData(data, true);
                                    }
                                    break;
                                case GAME_SERVER_CLIENT_SHAREEXTRAGAMEDATA_SET_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]SetClientShareExtraGameData ERROR:" << data;
                                        emit s_SetClientShareExtraGameData(data, false);
                                    }
                                    break;
                                }
                            }
                            break;


                        case GAME_SERVER_CLIENT_DISCONNECT:
                            {
                                sock->recievedData() >> m_nDisconnectCode;
                                m_pGameSocket->close();
                            }
                            break;




                        //数据库操作
                        case GAME_SERVER_SETDATA:
                            {
                                qint32 dataType, dataValue, operationID;
                                sock->recievedData() >> dataType >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapSetGameDataToNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_SETDATA_SUCCESS:
                                    {
                                        sock->recievedData() >> data;
                                        qDebug() << "[GameManager]SetGameDataToNetDB Success:" << data;
                                        emit s_SetGameDataToNetDB(dataType, dataValue, data, true, jsCallbackFunc);

                                        /*if(jsCallbackFunc.isCallable())
                                            jsCallbackFunc.call(QJSValueList() << 0 << data << dataType << dataValue);
                                            */
                                    }
                                    break;
                                case GAME_SERVER_SETDATA_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]SetGameDataToNetDB ERROR:" << data;
                                        emit s_SetGameDataToNetDB(dataType, dataValue, data, false, jsCallbackFunc);

                                        /*if(jsCallbackFunc.isCallable())
                                            jsCallbackFunc.call(QJSValueList() << 0 << QJSValue() << dataType << dataValue);
                                            */
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GETDATA:
                            {
                                qint32 dataType, dataValue, operationID;
                                QVariantList listData;
                                sock->recievedData() >> dataType >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapGetGameDataToNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_GETDATA_SUCCESS:
                                    {
                                        sock->recievedData() >> listData;
                                        qDebug() << "[GameManager]GetGameDataToNetDB Success:" << listData.length();

                                        emit s_GetGameDataToNetDB(listData, dataType, dataValue, data, true, jsCallbackFunc);


                                        /*if(jsCallbackFunc.isCallable())
                                            jsCallbackFunc.call(QJSValueList() << 0 << (QJSValueList)listData << dataType << dataValue);
                                            */
                                    }
                                    break;
                                case GAME_SERVER_GETDATA_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]GetGameDataToNetDB ERROR:" << data;
                                        emit s_GetGameDataToNetDB(listData, dataType, dataValue, data, false, jsCallbackFunc);
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_DELETEDATA:
                            {
                                qint32 dataType, dataValue, operationID;
                                sock->recievedData() >> dataType >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapDeleteGameDataToNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_DELETEDATA_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]DeleteGameDataToNetDB Success";
                                        emit s_DeleteGameDataToNetDB(dataType, dataValue, data, true, jsCallbackFunc);
                                    }
                                    break;
                                case GAME_SERVER_DELETEDATA_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]DeleteGameDataToNetDB ERROR:" << data;
                                        emit s_DeleteGameDataToNetDB(dataType, dataValue, data, false, jsCallbackFunc);
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_INSERTDATA:
                            {
                                qint32 dataType, dataValue, operationID;
                                sock->recievedData() >> dataType >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapInsertGameDataToNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_INSERTDATA_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]InsertGameDataToNetDB Success";
                                        emit s_InsertGameDataToNetDB(dataType, dataValue, data, true, jsCallbackFunc);
                                    }
                                    break;
                                case GAME_SERVER_INSERTDATA_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]InsertGameDataToNetDB ERROR:" << data;
                                        emit s_InsertGameDataToNetDB(dataType, dataValue, data, false, jsCallbackFunc);
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_UPDATEDATA:
                            {
                                qint32 dataType, dataValue, operationID;
                                sock->recievedData() >> dataType >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapUpdateGameDataToNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_UPDATEDATA_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]UpdateGameDataToNetDB Success";
                                        emit s_UpdateGameDataToNetDB(dataType, dataValue, data, true, jsCallbackFunc);
                                    }
                                    break;
                                case GAME_SERVER_UPDATEDATA_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]UpdateGameDataToNetDB ERROR:" << data;
                                        emit s_UpdateGameDataToNetDB(dataType, dataValue, data, false, jsCallbackFunc);
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_DBQUERY:
                            {
                                qint32 dataValue, operationID;
                                sock->recievedData() >> dataValue >> operationID >> data;
                                QJSValue jsCallbackFunc = m_mapQueryNetDBFunctionCache.take(operationID);

                                switch(data)
                                {
                                case GAME_SERVER_DBQUERY_SUCCESS:
                                    {
                                        qint32 rowsAffected;
                                        QVariant lastInsertID;
                                        QVariantList list;
                                        sock->recievedData() >> rowsAffected >> lastInsertID >> list;
                                        qDebug() << "[GameManager]NetDBQuery Success";
                                        emit s_NetDBQuery(dataValue, rowsAffected, lastInsertID, list, 0, true, jsCallbackFunc);
                                    }
                                    break;
                                case GAME_SERVER_DBQUERY_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]NetDBQuery ERROR:" << data;
                                        emit s_NetDBQuery(dataValue, -1, -1, QVariantList(), data, false, jsCallbackFunc);
                                    }
                                    break;
                                }
                            }
                            break;

                        }
                    }
                    break;



                case GAME_SERVER_GROUP:
                    {
                        sock->recievedData() >> data;
                        switch(data)
                        {
                        //群操作
                        case GAME_SERVER_GROUP_CREATE:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_CREATE_SUCCESS:
                                    {
                                        qint32 groupID;
                                        sock->recievedData() >> groupID;    //m_pGameCore->m_GameInfo.m_nGroupId;
                                        qDebug() << "[GameManager]创建房间成功:" << groupID;
                                        emit s_qml_CreateGroup(groupID, true, 0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_CREATE_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]创建房间ERROR:" << data;
                                        emit s_qml_CreateGroup(-1, false, data);
                                    }
                                    break;
                                }
                            }
                            break;
                        case GAME_SERVER_GROUP_CLOSE:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_CLOSE_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]关闭房间成功";
                                        emit s_qml_CloseGroup(true, 0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_CLOSE_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]关闭房间ERROR:" << data;
                                        emit s_qml_CloseGroup(false, data);
                                    }
                                    break;
                                }
                            }
                            break;
                        case GAME_SERVER_GROUP_UPDATE:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_UPDATE_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]更新房间信息成功";
                                        emit s_qml_UpdateGroup(true, 0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_UPDATE_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]更新房间信息ERROR:" << data;
                                        emit s_qml_UpdateGroup(false, data);
                                    }
                                    break;
                                }
                            }
                            break;
                        case GAME_SERVER_GROUP_SENDALLGROUPINFOS:
                            {
                            }
                            break;

                        case GAME_SERVER_GROUP_JOINGROUP:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_JOINGROUP_SUCCESS:
                                    {
                                        if(m_pGameSocket->getGroupID() > 0)
                                        {
                                            sock->clearGroupInfo();

                                            qDeleteAll(m_mapPlayerInGroupInfo);
                                            m_mapPlayerInGroupInfo.clear();

                                            emit s_qml_ExitGroup(true, 0);
                                            qDebug() << "[GameManager]退出旧房间成功";
                                        }


                                        qint32 groupMaxPlayerCount, index, count;
                                        bool bRunning;
                                        sock->recievedData() >> sock->m_ClientGroupInfo.m_nGroupId
                                                             >> sock->m_ClientGroupInfo.m_strPassword
                                                             >> groupMaxPlayerCount
                                                             >> index
                                                             >> bRunning
                                                             >> sock->m_ClientGroupInfo.m_vGroupData;
                                        sock->recievedData() >> count;

                                        if(index == -1)
                                            m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_ReadyToWatch);
                                        else
                                            m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_Waiting);

                                        sock->setGroupMaxPlayerCount(groupMaxPlayerCount);
                                        sock->setGroupIndex(index);
                                        sock->setGroupPlayerCount(count);

                                        qDebug() << "[GameManager]JoinGroup信息:" << sock->m_ClientGroupInfo.m_nGroupId << groupMaxPlayerCount << index;


                                        //接受群里客户信息
                                        for(qint32 i = 0; i < count; i++)
                                        {
                                            qint16 clientGroupStatus;
                                            PlayerInfo *playerinfo = new PlayerInfo(this);
                                            sock->recievedData() >> playerinfo->m_nSocketID
                                                                 >> playerinfo->m_nIndex
                                                                 >> playerinfo->m_unUserGameID
                                                                 >> playerinfo->m_bIsGroupMaster
                                                                 >> clientGroupStatus
                                                                 >> playerinfo->m_strNickname
                                                                 >> playerinfo->m_nSex
                                                                 >> playerinfo->m_nScore
                                                                 >> playerinfo->m_nServerID
                                                                 >> playerinfo->m_vExtraData
                                                                    ;
                                            playerinfo->m_ClientGroupStatus = (_ClientGroupStatus)clientGroupStatus;

                                            m_mapPlayerInGroupInfo.insert(playerinfo->m_nIndex, playerinfo);
                                        }


                                        emit s_qml_JoinGroup(sock->m_ClientGroupInfo.m_nGroupId, bRunning, true, 0);
                                        //QMessageBox::information(pRegister,tr("加入房间"),tr("加入成功"));
                                        //pCenter->setStatus(1);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_JOINGROUP_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        emit s_qml_JoinGroup(0, false, false, data);
                                        switch(data)
                                        {
                                        case -1:
                                            //QMessageBox::information(pLoginBox,tr("加入房间失败"),tr("没有此房间"));
                                            //m_pGameCore->setClientGroupStatus(_ClientGroupStatus::Game_Nothing);
                                            break;
                                        case -2:
                                            //QMessageBox::information(pLoginBox,tr("加入房间失败"),tr("所有房间已满"));
                                            //m_pGameCore->setClientGroupStatus(_ClientGroupStatus::Game_Nothing);
                                            break;
                                        case -3:
                                            //QMessageBox::information(pLoginBox,tr("加入房间失败"),tr("此房间正在游戏中"));
                                            //m_pGameCore->setClientGroupStatus(_ClientGroupStatus::Game_Nothing);
                                            break;
                                        case -4:
                                            //QMessageBox::information(pLoginBox,tr("加入房间失败"),tr("您已经加入了某个房间,请先退出"));
                                            //m_pGameCore->setClientGroupStatus(_ClientGroupStatus::Game_Nothing);
                                            break;
                                        default:
                                            //QMessageBox::information(pLoginBox,tr("加入房间失败"),tr("未知错误"));
                                            //m_pGameCore->setClientGroupStatus(_ClientGroupStatus::Game_Nothing);
                                            break;
                                        }
                                        //pCenter->setStatus(0);
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GROUP_REJOINRUNNINGGROUP:
                            {
                                //sock->clearGroupInfo();
                                m_pGameSocket->setGroupMaster(false);

                                qDeleteAll(m_mapPlayerInGroupInfo);
                                m_mapPlayerInGroupInfo.clear();

                                emit s_qml_ExitGroup(true, 0);
                                qDebug() << "[GameManager]退出房间成功";



                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_REJOINRUNNINGGROUP_SUCCESS:
                                    {
                                        qint32 socketID, oldSocketID, groupIndex;
                                        qint32 count;

                                        sock->recievedData() >> socketID >> groupIndex >> oldSocketID;
                                        sock->recievedData() >> count;

                                        if(groupIndex == -1)
                                            qCritical() << "[!GameManager]ReJoining GroupIndex ERROR:-1";
                                        if(m_pGameSocket->getGroupID() > 0)
                                        {
                                            qCritical() << "[!GameManager]ReJoining GroupID ERROR:" << m_pGameSocket->getGroupID();
                                        }

                                        m_pGameSocket->setClientGroupStatus(_ClientGroupStatus::GroupStatus_ReJoining);

                                        //sock->setGroupMaxPlayerCount(groupMaxPlayerCount);
                                        //sock->setGroupIndex(groupIndex);
                                        sock->setGroupPlayerCount(count);
                                        qDebug() << "[GameManager]ReJoinRunningGroup信息:" << socketID << oldSocketID << groupIndex << count;


                                        //接受群里客户信息
                                        for(qint32 i = 0; i < count; i++)
                                        {
                                            qint16 clientGroupStatus;
                                            PlayerInfo *playerinfo = new PlayerInfo(this);
                                            sock->recievedData() >> playerinfo->m_nSocketID
                                                                 >> playerinfo->m_nIndex
                                                                 >> playerinfo->m_unUserGameID
                                                                 >> playerinfo->m_bIsGroupMaster
                                                                 >> clientGroupStatus
                                                                 >> playerinfo->m_strNickname
                                                                 >> playerinfo->m_nSex
                                                                 >> playerinfo->m_nScore
                                                                 >> playerinfo->m_nServerID
                                                                 >> playerinfo->m_vExtraData
                                                                    ;
                                            playerinfo->m_ClientGroupStatus = (_ClientGroupStatus)clientGroupStatus;

                                            m_mapPlayerInGroupInfo.insert(playerinfo->m_nIndex, playerinfo);
                                        }

                                        emit s_qml_ReJoinRunningGroup(socketID, oldSocketID, groupIndex, true, 0);

                                        sl_StartGame(true, true);

                                    }
                                    break;
                                case GAME_SERVER_GROUP_REJOINRUNNINGGROUP_FAIL:
                                    {
                                        sock->clearGroupInfo();

                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]ReJoinRunningGroup ERROR:" << data;
                                        emit s_qml_ReJoinRunningGroup(-1, -1, -1, false, data);

                                        m_pGameCore->sl_OverGame(GameModel::Game_Status_Terminated, -3);
                                    }
                                    break;
                                }

                            }
                            break;

                        case GAME_SERVER_GROUP_EXITGROUP:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_EXITGROUP_SUCCESS:
                                    {
                                        sock->clearGroupInfo();

                                        qDeleteAll(m_mapPlayerInGroupInfo);
                                        m_mapPlayerInGroupInfo.clear();

                                        emit s_qml_ExitGroup(true, 0);
                                        qDebug() << "[GameManager]退出房间成功";
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("成功"));
                                        //pCenter->setStatus(0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_EXITGROUP_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        emit s_qml_ExitGroup(false, data);
                                        qCritical() << "[!GameManager]退出房间 ERROR:" << data;
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("失败"));
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GROUP_SETMASTER:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_SETMASTER_SUCCESS:
                                    {
                                        bool bMaster;
                                        sock->recievedData() >> bMaster;
                                        if(bMaster)
                                        {
                                            //quint32 masterUserGameID;
                                            qint32 masterIndex;
                                            bool bRunning, bAllDataIsEmpty;
                                            sock->recievedData() >> masterIndex >> bRunning >> bAllDataIsEmpty;
                                            //if(masterUserGameID == m_pUserInfo->m_GameServerUserInfo.unUserGameID)
                                            if(masterIndex == m_pGameSocket->getGroupIndex())
                                            {
                                                m_pGameSocket->setGroupMaster(bMaster);
                                            }
                                            PlayerInfo *playerinfo = qobject_cast<PlayerInfo*>(m_mapPlayerInGroupInfo.value(masterIndex));
                                            playerinfo->m_bIsGroupMaster = bMaster;

                                            emit s_qml_SetMaster(playerinfo, bMaster, bRunning, bAllDataIsEmpty, true, 0);

                                            qDebug() << "[GameManager]房主设置成功";
                                        }
                                        else
                                        {
                                            bool bRunning, bAllDataIsEmpty;
                                            sock->recievedData() >> bRunning >> bAllDataIsEmpty;

                                            //!!!!!!!!!!这里应该还要设置 masterPlayerinfo 的 master 为 false
                                            if(m_pGameSocket->isGroupMaster())
                                            {
                                                m_pGameSocket->setGroupMaster(bMaster);
                                            }

                                            emit s_qml_SetMaster(nullptr, bMaster, bRunning, bAllDataIsEmpty, true, 0);

                                            qWarning() << "[!GameManager]房主取消成功:" << bRunning;
                                        }
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("成功"));
                                        //pCenter->setStatus(0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_SETMASTER_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        emit s_qml_SetMaster(nullptr, false, false, false, false, data);
                                        qCritical() << "[!GameManager]房主设置ERROR:" << data;
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("失败"));
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GROUP_GETREADY:
                            {
                                sock->recievedData() >> data;

                                switch(data)
                                {
                                case GAME_SERVER_GROUP_GETREADY_SUCCESS:
                                    {
                                        //quint32 userGameID;
                                        qint32 groupIndex;
                                        sock->recievedData() >> groupIndex >> data;

                                        //if(m_pUserInfo->m_GameServerUserInfo.unUserGameID == groupIndex)
                                        if(groupIndex == m_pGameSocket->getGroupIndex())
                                            m_pGameSocket->setClientGroupStatus(data);

                                        PlayerInfo *playerinfo = qobject_cast<PlayerInfo*>(m_mapPlayerInGroupInfo.value(groupIndex, nullptr));
                                        playerinfo->m_ClientGroupStatus = (_ClientGroupStatus)data;

                                        emit s_qml_GetReady(playerinfo, true, data);
                                        qDebug() << "[GameManager]切换状态成功:" << data;
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("成功"));
                                        //pCenter->setStatus(0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_GETREADY_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        emit s_qml_GetReady(nullptr, false, data);
                                        qCritical() << "[!GameManager]切换状态 ERROR:" << data;
                                        //QMessageBox::information(pRegister,tr("退出房间"),tr("失败"));
                                    }
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GROUP_KICK:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_KICK_SUCCESS:
                                    {
                                        qDebug() << "[GameManager]踢人成功";
                                        emit s_qml_GroupKick(true, 0);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_KICK_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]踢人ERROR:" << data;
                                        emit s_qml_GroupKick(false, data);
                                    }
                                    break;
                                }
                            }
                            break;


                        case GAME_SERVER_GROUP_RELEASEGROUPINDEX:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_RELEASEGROUPINDEX_SUCCESS:
                                    {
                                    }
                                    break;
                                case GAME_SERVER_GROUP_RELEASEGROUPINDEX_FAIL:
                                    {
                                        sock->recievedData() >> data;
                                        qCritical() << "[!GameManager]ReleaseGroupIndex ERROR:" << data;
                                    }
                                    break;
                                }
                            }
                            break;
                        case GAME_SERVER_GROUP_OTHERSINFO:
                            {
                                sock->recievedData() >> data;
                                switch(data)
                                {
                                case GAME_SERVER_GROUP_OTHERSINFO_JOINGROUP:
                                    {
                                        qint32 socketID;
                                        qint32 groupIndex;
                                        quint32 userGameID;
                                        bool bIn;
                                        bool bRunning;
                                        bool bResetFrame;

                                        sock->recievedData() >> socketID >> groupIndex >> userGameID
                                                             >> bRunning >> bResetFrame >> bIn;
                                        if(bIn)
                                        {
                                            PlayerInfo *playerinfo = new PlayerInfo(this);   //"this" is running correct!
                                            sock->recievedData() >> playerinfo->m_bIsGroupMaster
                                                                 >> playerinfo->m_strNickname
                                                                 >> playerinfo->m_nSex
                                                                 >> playerinfo->m_nScore
                                                                 >> playerinfo->m_nServerID
                                                                 >> playerinfo->m_vExtraData
                                                                    ;
                                            playerinfo->m_nSocketID = socketID;
                                            playerinfo->m_nIndex = groupIndex;
                                            playerinfo->m_unUserGameID = userGameID;

                                            m_mapPlayerInGroupInfo.insert(groupIndex, playerinfo);
                                            sock->setGroupPlayerCount(sock->getGroupPlayerCount() + 1);
                                            emit s_qml_OthersJoinGroup(playerinfo, bRunning, bResetFrame, bIn, false);
                                        }
                                        else
                                        {
                                            bool bKeepGroupIndex;
                                            sock->recievedData() >> bKeepGroupIndex;

                                            sock->setGroupPlayerCount(sock->getGroupPlayerCount() - 1);
                                            PlayerInfo *playerinfo = qobject_cast<PlayerInfo*>(m_mapPlayerInGroupInfo.value(groupIndex, nullptr));
                                            emit s_qml_OthersJoinGroup(playerinfo, bRunning, bResetFrame, bIn, bKeepGroupIndex);

                                            if(!bKeepGroupIndex)
                                            {
                                                qDebug() << "[GameManager]客户退房间";
                                                delete m_mapPlayerInGroupInfo.take(groupIndex);
                                            }
                                            else
                                            {
                                                qDebug() << "[GameManager]客户断线缓存:" << userGameID << groupIndex;
                                                m_mapDisconnectClientInfo.insert(userGameID, groupIndex);
                                            }
                                        }
                                    }
                                    break;

                                case GAME_SERVER_GROUP_OTHERSINFO_REJOINRUNNINGGROUP:
                                    {
                                        qint32 socketID;
                                        qint32 groupIndex;
                                        qint32 oldSocketID;
                                        quint32 userGameID;
                                        bool bIn;
                                        bool bRunning;
                                        bool bResetFrame;

                                        sock->recievedData() >> socketID >> groupIndex >> oldSocketID >> userGameID >> bRunning >> bResetFrame >> bIn;
                                        if(bIn)
                                        {
                                            if(m_mapDisconnectClientInfo.remove(userGameID) != 1)
                                                qCritical() << "[!GameManager]ReJoinRunningGroup ERROR:" << socketID << groupIndex << oldSocketID << userGameID;

                                            if(!m_mapPlayerInGroupInfo.contains(groupIndex))
                                            {
                                                qCritical() << "[!GameManager]ReJoinRunningGroup ERROR2:" << socketID << groupIndex << oldSocketID << userGameID;
                                                break;
                                            }
                                            //m_mapPlayerInGroupInfo.insert(socketID, m_mapPlayerInGroupInfo.value(oldSocketID));
                                            //m_mapPlayerInGroupInfo.remove(oldSocketID);

                                            emit s_qml_OthersReJoinRunningGroup(socketID, oldSocketID, groupIndex, userGameID, bRunning, bResetFrame, bIn);
                                        }
                                        else
                                        {
                                            qDebug() << "[GameManager]ReJoinRunningGroup FAIL!";
                                        }
                                    }
                                    break;


                                /*case GAME_SERVER_GROUP_OTHERSINFO_READY:
                                    {
                                        qint32 socketID;
                                        qint16 status;
                                        qint16 duiWu;
                                        sock->recievedData() >> socketID >> status >> duiWu;
                                        PlayerInfo *playerinfo = qobject_cast<PlayerInfo*>(m_mapPlayerInGroupInfo.value(socketID));
                                        emit s_qml_OthersReadyInGroup(playerinfo, status, duiWu);
                                    }
                                    break;*/

                                case GAME_SERVER_GROUP_OTHERSINFO_MESSAGE:
                                    {
                                        quint32 userGameID;
                                        qint16 type;
                                        QString message;
                                        sock->recievedData() >> userGameID >> type >> message;
                                        emit s_qml_OthersMessage(userGameID, type, message);
                                    }
                                    break;
                                case GAME_SERVER_GROUP_OTHERSINFO_DATA:
                                    break;
                                default:
                                    qCritical() << ("[!GameManager]GAME_SERVER_GROUP_OTHERSINFO ERROR!");
                                    break;
                                }
                            }
                            break;

                        case GAME_SERVER_GROUP_RANDOMNUMBER:
                            {
                                qint32 randomNumberID;
                                QList<qint32> randomNumber;
                                qint32 usePoint;
                                sock->recievedData() >> randomNumberID >> randomNumber >> usePoint;
                                sock->m_RandomNumber.initRandomNumber(randomNumberID, randomNumber, usePoint);
                                qDebug() << "[GameManager]RandomNumber:" << randomNumberID << usePoint;
                            }
                            break;

                        default:
                            qCritical() << ("[!GameManager]GAME_SERVER_GROUP ERROR:") << data;
                            break;
                        }
                    }
                    break;

                default:
                    qCritical() << ("[!GameManager]GAME_SERVER_RESPONSE ERROR:") << data;
                    break;
                }
            }
            break;


        case GAME_DATA:
            {
                /*if(m_pGameCore->m_pGameModel->gameStatus() != GameModel::Game_Status_Running)
                {
                    qCritical() << (_T("[!GameManager]Warning!接收GAME包时游戏已经结束:%1").arg(m_pGameCore->m_pGameModel->gameStatus()));
                    return;
                }*/

                sock->recievedData() >> data;
                qDebug() << "数据GAME_DATA类型2:" << data;
                switch(data)
                {
                case GAME_DATA_GAMEOVER:
                    {
                        qint16 status;
                        qint32 code;
                        sock->recievedData() >> status >> code;
                        qDebug() << "[GameManager]服务器游戏逻辑结束:" << status << code;
                        m_pGameCore->sl_OverGame((GameModel::_GameStatus)status, code);
                    }
                    break;

                case GAME_DATA_STARTGAME:
                    {
                        sock->recievedData() >> data;
                        switch(data)
                        {
                        case GAME_DATA_STARTGAME_SUCCESS:
                            {
                                bool isStarted;
                                sock->recievedData() >> isStarted;

                                qDebug() << "[GameManager]开始游戏成功:" << isStarted;
                                //QMessageBox::information(pRegister,tr("退出房间"),tr("成功"));
                                //pCenter->setStatus(0);


                                //传递所有武将信息！！！
                                //sock->recievedData() >> data;
                                //m_pGameCore->m_nPlayerCount = data;

                                //QVector<quint32> playerGameIDArray;
                                //QVector<qint16> playerDuiWuArray;
                                //QList<qint32> playerJiaoSeList;

                                //sock->recievedData() >> playerGameIDArray >> playerDuiWuArray;
                                //sock->recievedData() >> playerJiaoSeList;

                                //设置所有角色的m_eJiaoSe!
                                /*int i = 0;
                                for(i = 0; i < m_pGameCore->m_nPlayerCount; i++)
                                {
                                    qint32 index;       //在服务器上的序号(非id)
                                    qint32 socketID;
                                    qint16 duiwu;
                                    //sock->recievedData() >> duiwu;  //没用，根据socketID来检测是否是本人
                                    sock->recievedData() >> index;
                                    sock->recievedData() >> socketID;
                                    //sock->recievedData() >> m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname;
                                    sock->recievedData() >> duiwu;

                                    m_pGameCore->m_arrayPlayer[i].m_nDuiWu = duiwu;

                                    //QLinkedList list;


                                    //如果是本人
                                    if(socketID == m_pGameSocket->m_nSocketID)
                                    {
                                        m_pGameCore->m_nMyID = i;
                                        m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_Self;


                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname = m_pUserInfo->nickName();
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nSex = m_pUserInfo->sex();
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nServerID = m_pUserInfo->serverID();
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nGradeID = m_pUserInfo->gradeID();
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nScore = m_pUserInfo->scoreCount();

                                    }
                                    / *else if(playerGameIDArray.at(i) == -1)
                                    {
                                        m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_Self;
                                    }* /
                                    else if(socketID == -1)   //电脑
                                    {
                                        m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_AI;

                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname = "【小艾】";
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nSex = Random(0,2);
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nServerID = -1;
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nGradeID = -1;
                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nScore = Random(0, 100000000);
                                    }
                                    else            //其他网络玩家
                                    {
                                        m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = _Player::JiaoSe_Others;

                                        //_Player::PlayerInfo playerinfo = {};
                                        //playerinfo.m_strNickname = "[AI]";
                                        //playerinfo.m_nSex = 1;

                                        m_pGameCore->m_arrayPlayer[i].m_PlayerInfo = qobject_cast<PlayerInfo*>(m_mapPlayerInGroupInfo.value(socketID));
                                        //m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_strNickname = playerinfo.m_strNickname;
                                        //m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nSex = playerinfo.m_nSex;
                                        //m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nServerID = playerinfo.m_nServerID;
                                        //m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nGradeID = playerinfo.m_nGradeID;
                                        //m_pGameCore->m_arrayPlayer[i].m_PlayerInfo.m_nScore = playerinfo.m_nScore;

                                    }

                                    //m_pGameCore->m_arrayPlayer[i].m_eJiaoSe = (_Player::JiaoSe)playerJiaoSeList[i];
                                }
                                / *
                                QList<qint16>::iterator ii;
                                for (ii = playerTypeList.begin(); ii != playerTypeList.end(); ++ii)
                                {
                                       m_pGameCore->m_arrayPlayer[i].iJiaoSe = *ii;
                                }*/

                                //qDebug() << "StartGame:" << m_pGameCore->m_nMyID << m_pGameCore->m_nPlayerCount << m_pGameCore->m_bLogicalMaster;

                                sl_StartGame(true, isStarted);
                            }
                            break;
                        case GAME_DATA_STARTGAME_FAIL:
                            {
                                sock->recievedData() >> data;
                                qCritical() << "[!GameManager]开始游戏 ERROR:" << data;
                                //QMessageBox::information(pRegister,tr("退出房间"),tr("失败"));
                            }
                            break;
                        }
                    }
                    break;

                case GAME_DATA_TRANSFER_DATA:
                    {
                        quint32 userGameID;
                        QVariantMap mapData;
                        sock->recievedData() >> userGameID >> mapData;
                        qDebug() << "[GameManager]GameTransferData";
                        emit s_GameTransferData(userGameID, mapData);
                    }
                    break;

                case GAME_DATA_SYNC_DATA:
                    {
                        quint32 userGameID;
                        QVariantMap mapData;
                        sock->recievedData() >> userGameID >> mapData;
                        qDebug() << "[GameManager]GameSyncData";
                        emit s_GameSyncData(userGameID, mapData);
                    }
                    break;

                case GAME_DATA_FRAME_DATA:
                    {
                        quint32 frameIndex;
                        QVariantList listData;
                        sock->recievedData() >> frameIndex >> listData;

                        if(frameIndex == sock->m_ClientGroupInfo.m_unFrameIndex)
                            qDebug() << "[GameManager]GameFrameData:" << frameIndex;
                        else
                            qWarning() << "[!GameManager]GameFrameData WARNING:" << frameIndex << sock->m_ClientGroupInfo.m_unFrameIndex;

                        emit s_GameFrameData(frameIndex, listData);

                        sock->m_ClientGroupInfo.m_unFrameIndex++;
                    }
                    break;

                case GAME_DATA_SYNC_ALLDATA:
                    {
                        QVariantMap data;
                        QVariantList datalist;
                        qint32 randomNumberID;
                        QList<qint32> randomNumber;
                        qint32 usePoint;
                        qint32 sendFrameCount;

                        sock->recievedData() >> sock->m_ClientGroupInfo.m_unFrameIndex >> randomNumberID >> randomNumber >> usePoint >> data >> datalist >> sendFrameCount;

                        sock->m_RandomNumber.initRandomNumber(randomNumberID, randomNumber, usePoint);

                        qDebug() << "[GameManager]GameSyncAllData:" << randomNumberID << usePoint << sendFrameCount;
                        emit s_GameSyncAllData(sock->m_ClientGroupInfo.m_unFrameIndex, sendFrameCount, data, datalist);
                    }
                    break;

                /*case GAME_...:    //游戏数据
                    {
                        qDebug() << "数据接收处理中:";
                        _GameData *pData = new _GameData;
                        if(pData == nullptr)
                        {
                            m_pGameCore->TerminateGame(GameCore::Game_Status_ERROR, -100);
                            return;
                        }


                        pData->type = data;


                        sock->recievedData() >> pData->XXXData.iData;
                        sock->recievedData() >> pData->XXXData.dataLength;


                        pData->ChuPaiData.data = new char[pData->ChuPaiData.dataLength];
                        if(pData->ChuPaiData.data == nullptr)
                        {
                            delete pData;
                            m_pGameCore->TerminateGame(GameCore::Game_Status_ERROR, -11);
                            return;
                        }

                        int ret = sock->recievedData().readRawData(pData->XXXData.data,pData->XXXData.dataLength);
                        if(ret != pData->XiPaiData.dataLength)
                        {
                            Debug(tr("读取数据出错:%1").arg(ret));
                            delete pData->ChuPaiData.data;
                            delete pData;
                            m_pGameCore->TerminateGame(GameCore::Game_Status_ERROR, -11);
                            return;
                        }

                        if(!pData->CheckGameData())
                        {
                            if(pData != nullptr)delete pData;
                            m_pGameCore->TerminateGame(GameCore::Game_Status_ERROR, -51);
                            return;
                        }
                        m_pGameCore->m_Producer.safeIn(pData);
                        qDebug() << "数据接收处理完毕:";
                    }
                    break;*/

                default:
                    qCritical() << (tr("[!GameManager]GAME_DATA通信 ERROR"));
                    break;
                }
            }
            break;

        default:
            qCritical() << "[!GameManager]数据 ERROR:" << data;
            break;
        }   //switch(data)

        /*
        int id;
        sock->recievedData() >> id;
        qDebug() << (QString("包ID:%1").arg(id));
        */


    }
    return;
}

void GameManager::OnGameReadyRead(TcpSocket* sock)
{
    qint16 data;

    //uint datalen = sock->recievedDataSize();
    //if(m_pGameCore->isMaster)
    //    qDebug() << "主机客户端接收数据大小:" << datalen;
    //else
    //    qDebug() << "副机客户端接收数据大小:" << datalen;


    //QDataStream dsData(baData);
    //while(!sock->recievedData().atEnd())
    //if(!sock->recievedData().atEnd())     //不能判断数据是否空,因为有些没有数据,比如8d类型
    {
        switch(sock->m_ucInControlByte)
        {
        case TRANSMIT_SOCKET_ID:
            return;
        case TRANSMIT_CODE_RECIEVED:
            return;
        case TRANSMIT_CODE_DATA:
            break;

        default:
            break;
        }


        sock->recievedData() >> data;
        qDebug() << "数据类型1:" << data;
        switch(data)
        {
        /*case :
            {
                //int datalen = sock->recievedDataSize();
                sock->recievedData() >> data;
                switch(data)
                {
                    default:
                    break;
                }
                int i = sock->recievedData().readRawData(data,datalen);
            }
            break;
        */
        default:
            //m_pGameWindow->scene->ShowDebug(tr("主通信错误%1").arg(data));
            break;
        }   //switch(data)
    }
    return;
}


void GameManager::sl_qml_DebugButton(int button, QVariant v)
{
    //显示发送Socket的信息
    if(button == 10)
    {
        qDebug() << m_pInfoSocket->sendDataValid() << m_pInfoSocket->sendData().device()->pos() << m_pInfoSocket->sendData().device()->bytesAvailable();
        showHex(m_pInfoSocket->getOutBlock().data(),m_pInfoSocket->getOutBlock().length());
    }
    //显示发送Socket的信息
    else if(button == 11)
    {
        m_pGameSocket->sendData();
        m_pGameSocket->send(TRANSMIT_OTHER_TYPE, false);
    }
    //显示发送Socket的信息
    else if(button == 12)
    {
        m_pGameSocket->close();
    }

    //发送v
    else if(button == 1)
    {
        m_pInfoSocket->sendData() << (qint16)INFO_SERVER_REQUEST
                                  << (qint16)INFO_SERVER_CLIENT
                                  << (qint16)v.toInt();
        m_pInfoSocket->send(TRANSMIT_OTHER_TYPE);
    }
    else if(button == 2)
    {
        qDebug() << "sl_qml_DebugButton:" << v
                 << v.toInt() << v.toString()
                 << v.type() << v.userType() << v.typeName()
                 << v.canConvert<int>() << v.canConvert<QString>();
        if(v.canConvert<QJSValue>())
        {
            QVariant vv = v.value<QJSValue>().toVariant();
            qDebug() << "JSValue:" << vv
                     << vv.toInt() << vv.toString()
                     << vv.type() << vv.userType() << vv.typeName()
                     << vv.canConvert<int>() << vv.canConvert<QString>()
                     << vv.canConvert<QVariantMap>() << vv.canConvert<QVariantList>()
                     << "tomap/list:" << v.toMap() << v.toList();
        }
    }
    else if(button == 31)
    {
        //初始化为对象
        sl_qml_SetClientShareExtraGameData("{}", "$");
        //赋值
        sl_qml_SetClientShareExtraGameData(v, "$.\"0\"");
        sl_qml_SetClientShareExtraGameData(v, "$.key");

        //初始化为数组
        sl_qml_SetClientShareExtraGameData("[]", "$");
        //赋值
        sl_qml_SetClientShareExtraGameData(v, "$[0]");
    }
    else if(button == 32)
    {
        qDebug() << m_pUserInfo->m_GameServerUserInfo.vExtraData;
    }
    else if(button == 33)
    {
        qDebug() << "Debug RandomNumber:" << m_pGameSocket->m_RandomNumber.m_nRandomNumberID
        << m_pGameSocket->m_RandomNumber.m_nUsePoint
        << m_pGameSocket->m_ClientGroupInfo.m_unFrameIndex;
    }
}
